package com.wow.wa.ui;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.View.MeasureSpec;

import com.wow.wa.ui.bean.UICategory;
import com.wow.wa.uicommon.R;

/**
 * 自製按鈕畫面
 * 
 * @author Andy
 * 
 */
public class ItemButton extends View {
	private static final String TAG = "ItemButton";
	private Context context;
	private Paint paint;
	private UICategory category;
	private int size = 50;
	private String title;

	public ItemButton(Context context, AttributeSet attrs) {
		super(context, attrs);
		this.context = context;

		final TypedArray a = getContext().obtainStyledAttributes(attrs,
				R.styleable.CategoryButton, 0, 0);
		this.title = a.getString(R.styleable.CategoryButton_title);

		paint = new Paint();
		this.paint.setColor(Color.BLACK);
		this.paint.setTextAlign(Align.LEFT);
		this.paint.setTextSize(size);// 设置字体大小
		// paint.setTypeface(typeface);//设置字体类型
		this.invalidate();
	}

	@Override
	protected void onDraw(Canvas canvas) {

		super.onDraw(canvas);

		String out = this.title + ":";
		if (category == null) {
			out += context.getString(R.string.clickToEnter);
		} else {
			out += this.category.getName();
		}
		canvas.drawText(out, 0 + 10, height, paint);

	}

	public void setContent(UICategory uiCategory) {
		this.category = uiCategory;
		this.invalidate();
	}

	private int width;
	private int height;

	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		this.width = MeasureSpec.getSize(widthMeasureSpec);
		this.height = MeasureSpec.getSize(heightMeasureSpec);
		Log.v(TAG, "width=" + width + ",height=" + height);
		// TODO Auto-generated method stub
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);
	}

	public UICategory getCategory() {
		return category;
	}

}
